import request from '@/utils/request'

interface LoginParam {
  username: string,
  password: string,
  code: string
}

/**
 * 登录
 * @param username 用户名 
 * @param password 密码
 * @param code 验证码
 * @returns 
 */
const login = (username: string,password: string,code: string, uuid: string) => {
  const data = {
    username,
    password,
    code,
    uuid
  }
  return request({
    method: 'post',
    url: '/users/login',
    data
  })
}

/**
 * 退出登录
 */
const logout = () => {
  return request({
    method: 'post',
    url: '/users/logout',
  })
}

/**
 * 注册
 * @param data 注册填入的表单数据
 * @returns 
 */
const register = (data: object) => {
  return request({
    method: 'post',
    url: '/users/register',
    data
  })
}

const getInfo = () => {
  return request({
    method: 'get',
    url: '/users/getInfo',
  })
}

const getCodeImage = () => {
  return request({
    method: 'post',
    url: '/codeImg',
  })
}

export default {
  login,
  register,
  logout,
  getInfo,
  getCodeImage
}